package com.jeecg.test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.jeecg.annotation.RequestMapping;
import com.jeecg.annotation.RequestParam;
import com.jeecg.bean.vo.MVCVO;
import com.jeecg.control.LoginAction;

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	String basePackage="com.jeect.*";
	int indexOfLast=basePackage.indexOf(".*");
	System.out.println(indexOfLast);
	System.out.println(basePackage.substring(0, indexOfLast));

	}

	public void init(){
		Class<?> clazz=null;
		try {
			clazz=Class.forName("com.jeecg.control.LoginAction");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		//如果有RequestMapping注解，则遍历类的方法
		if(clazz.isAnnotationPresent(RequestMapping.class)){
			RequestMapping classMapping=clazz.getAnnotation(RequestMapping.class);
			String classUrl=classMapping.value();
			Method []methods=clazz.getDeclaredMethods();
			for(Method m:methods){
				if(!m.isAnnotationPresent(RequestMapping.class))
					continue;
				
				RequestMapping methodMapping=m.getAnnotation(RequestMapping.class);
				//获取方法的url
				String methodUrl=methodMapping.value();
				String requurl=classUrl+methodUrl;
				//方法参数类型
				Class<?> [] pars=m.getParameterTypes();
				//方法参数名称
				List<String> paramsNames=new ArrayList();
				 Annotation[][] params= m.getParameterAnnotations(); 
				 for(Annotation[] annotations:params){
					 boolean flag=false;
					 for(Annotation annotation:annotations){
						 if(annotation instanceof RequestParam){
							 RequestParam an=(RequestParam)annotation;
							 paramsNames.add(an.value());
							 flag=true;
						 }
					 }
					 if(!flag){
						 paramsNames.add("");
					 }
				 }
				 //定义vo，把方法相关属性添加进去
				 MVCVO vo=new MVCVO();
				 vo.setClassType(clazz);
				 vo.setMethodName(m.getName());
				 vo.setParamsClass(pars);
				 vo.setParamsName(paramsNames);
				 System.out.println(vo);
			}
		}
	}
}
